package com.cqyc.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.comm.Pager;
import com.cqyc.shop.comm.commException;
import com.cqyc.shop.domain.Shop;
import com.cqyc.shop.services.ShopServices;

@WebServlet(urlPatterns="/advanceGood.do")
public class AdvanceGoodServlet extends HttpServlet{
	private static final long serialVersionUID = -489411324927815457L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private ShopServices shopServices = new ShopServices();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			Shop shop = new Shop();
					
			//特价秒杀区
			Pager pager_jrtj = new Pager();
			pager_jrtj.setPageSize(4);
			pager_jrtj.setCurrentPage(1);
			shop.setShopname("冰淇淋");
			
			
			List<Shop> shops_jrtj = shopServices.findPager(shop,pager_jrtj);

			request.setAttribute("shops_jrtj",shops_jrtj);
			
			//精品生鲜
			Pager pager_jpsx = new Pager();
			pager_jpsx.setPageSize(8);
			pager_jpsx.setCurrentPage(1);
			shop.setShopname("生鲜");
			
			
			List<Shop> shops_jpsx = shopServices.findPager(shop,pager_jpsx);

			request.setAttribute("shops_jpsx",shops_jpsx);
			
			
			
			//粮油冲品
			Pager pager_lycp = new Pager();
			pager_lycp.setPageSize(8);
			pager_lycp.setCurrentPage(1);
			shop.setShopname("粮油");
			
			
			List<Shop> shops_lycp = shopServices.findPager(shop,pager_lycp);

			request.setAttribute("shops_lycp",shops_lycp);
			
			
			//综合用品
			Pager pager_zhyp = new Pager();
			pager_zhyp.setPageSize(8);
			pager_zhyp.setCurrentPage(1);
			shop.setShopname("综合");
			
			
			List<Shop> shops_zhyp = shopServices.findPager(shop,pager_zhyp);

			request.setAttribute("shops_zhyp",shops_zhyp);

			
			logger.debug("查询数据成功");
			request.getRequestDispatcher("/advanceGood.jsp").forward(request, response);
		} catch (Exception e) {
			throw new commException("list查找出现异常");
		}
	}
	
	

}
